package com.ysxsoft.wdg.adapter.ht;


import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.response.HuiTaoResponse;
import com.ysxsoft.wdg.util.ViewUtils;

public class HtAdapter extends BaseQuickAdapter<HuiTaoResponse.DataBeanX.DataBean,BaseViewHolder> {

    private int type = 0;//0需要隐藏播放按钮

    public void setType(int type){
        this.type = type;
        notifyDataSetChanged();
    }

    public OnChangeListener listener;

    public void setListener(OnChangeListener listener) {
        this.listener = listener;
    }

    public HtAdapter(int layoutResId) {
        super(layoutResId);
    }

    public void clear(){
        getData().clear();
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, HuiTaoResponse.DataBeanX.DataBean item) {
        int position = helper.getLayoutPosition();

        helper.setText(R.id.tv_name,item.getTitle());
        helper.setText(R.id.tv_zan_num, item.getZan_num()+"");
        helper.setText(R.id.tv_nick,""+item.getUsername());

        Glide.with(mContext).load(item.getPic()).into((ImageView) helper.getView(R.id.iv_pic));
        ViewUtils.loadCircleImage(mContext,item.getAvatar(), (ImageView) helper.getView(R.id.iv_tx));

        ImageView ivPlay = helper.getView(R.id.iv_play);
        if(type==0){
            ivPlay.setVisibility(View.GONE);
        }else{
            ivPlay.setVisibility(View.VISIBLE);
        }

        ImageView delete=helper.getView(R.id.delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onDelete(item.getId()+"");
                }
            }
        });
    }

    public interface OnChangeListener{
        void onDelete(String id);
    }
}
